package com.jianyun.jyzs.http;

import android.content.Intent;
import android.os.Bundle;


import com.jianyun.jyzs.R;
import com.jianyun.jyzs.adapter.ContactModuleFmAdapter;
import com.jianyun.jyzs.bean.User;
import com.jianyun.jyzs.fragment.ContactFragment;
import com.jianyun.jyzs.utils.SysConstant2;

import java.util.ArrayList;

/**
 * 广播回调帮助类
 */
public class ContactModuleFmBroadHelper {

    public static void onReceiveBroadCast(ContactFragment fm, Intent intent) {
        try {
            Bundle bundle = intent.getExtras();
            String userId = bundle.getString(SysConstant2.msg_key_string1);
            switch (bundle.getInt(SysConstant2.dataType)) {
                case SysConstant2.tp_addCommonContact:
                   /* fm.users_temp = new ArrayList<User>();
                    int count = 0;
                    for (User user : fm.contactList) {
                        if (user.getServerUserId().equals(userId)) {
                            user.setIsCommonContact(1);
                        }
                        if (user.getIsCommonContact() != null && user.getIsCommonContact().intValue() >= 1) {
                            fm.users_temp.add(user);
                            count++;
                        }
                    }
                    if (fm.tv_selContacts.getText().toString().equals(fm.getString(R.string.text_commonContact))) {
                        fm.adapter = new ContactModuleFmAdapter(fm.act, R.layout.item_contact_list, fm.users_temp);
                        fm.listView.setAdapter(fm.adapter);
                        fm.tv_total.setText(String.valueOf(count) + "位常用联系人");
                        fm.adapter.notifyDataSetChanged();
                    }*/
                    break;
                case SysConstant2.tp_deleteCommonContact:
                    /*for (User user : fm.contactList) {
                        if (user.getServerUserId().equals(userId)) {
                            if (fm.users_temp != null) {
                                for (User userT : fm.users_temp) {
                                    if (userT.getServerUserId().equals(userId)) {
                                        fm.users_temp.remove(userT);
                                        break;
                                    }
                                }
                            }
                            user.setIsCommonContact(0);
                            if (fm.tv_selContacts.getText().toString().equals(fm.getString(R.string.text_commonContact))) {
                                fm.adapter = new ContactModuleFmAdapter(fm.act, R.layout.item_contact_list, fm.users_temp);
                                fm.listView.setAdapter(fm.adapter);
                                fm.tv_total.setText(String.valueOf(fm.users_temp.size()) + "位常用联系人");
                                fm.adapter.notifyDataSetChanged();
                            }
                            break;
                        }
                    }*/
                    break;
                default:
                    break;
            }
        } catch (Exception e) {
        }
    }
}

